package com.zhang.gmall.logger.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 日志采集服务
 * @title: 日志转发到kafka
 * @author: zhang
 * @date: 2022/2/28 19:51
 */
@RestController
@Slf4j
public class LoggerController {
    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    @RequestMapping("/applog")
    public String logger(@RequestParam("param") String logStr){
        //打印控制台
        System.out.println(logStr);
        //落盘--使用第三方日志框架，logback完成
        log.info(logStr);
        //发送kafka主题
        kafkaTemplate.send("ods_base_log_2022",logStr);
        return "success";
    }
}
